/*
 ============================================================================
 Name        : common.h
 Author      :
 Version     :
 Copyright   : Your copyright notice
 Description :
 ============================================================================
 */

#ifndef COMMOND_H_
#define COMMOND_H_

#define UINT8  unsigned char ///< One byte
#define UINT32 unsigned int ///< One instruction
#define INT32  int
#define INT8  	char

#define BYTE(x) (x*8) ///< One byte
#define BIT2BYTE(x) (x/8)+(x%8?1:0) ///< One byte in binary

typedef struct _addresingAndType
/// Stores the attributes that specifies the addressing method.
{
	INT8 a[10]; ///< Addressing Method
	INT8 t[10];	///< Operand Type
	INT8 flds[10]; ///< Opcode Fields
} ADDRESSING_TYPE;


typedef struct _prefix
/// Structure attributes associated with a prefix.
{
	unsigned char value;
} PREFIX;

typedef union _opcode
/// Stores the attributes that an opcode have.
{
	unsigned char value; ///< Operation code value
	struct
	{
		unsigned char opcode :6; ///< Operation code
		unsigned char d :1; ///< Attribute direction
		unsigned char s :1; ///< Attribute store
	};
} OPCODE;


typedef union _mod_reg
/// Stores ModReg record attributes you set the registers used as operands.
{
	unsigned char value;
	struct
	{
		unsigned char mod :2;
		unsigned char reg_opcode :3;
		unsigned char rm :3;
	};
} MOD_REG_RM;

#define NUM_OPP_SUPPORTED 2

typedef struct _MachineInstFormat
/// Machine Instruction Format
{
	INT8 mnemonic[8]; ///< mnemonic

	UINT8 isPrefix; ///< Prefix value
	PREFIX prefix;

	OPCODE opcode; ///< Operation Code

	UINT8 regOpValid[NUM_OPP_SUPPORTED];
	UINT8 regOpp[NUM_OPP_SUPPORTED][5];

	UINT8 isModeReg; ///< If  it is a ModReg register
	UINT8 regOrg[3];
	UINT8 regDst[3];
	MOD_REG_RM mod_reg_rm;

	UINT8 opSize[NUM_OPP_SUPPORTED]; ///< Operation Code Size
	UINT8 opValid[NUM_OPP_SUPPORTED]; ///< If  it is an operation code valid
	UINT8 op[NUM_OPP_SUPPORTED][128];///< Operation Code
} MACHINE_INSTRUCTION;
typedef struct
/// Properties of an operation code.
{
	INT8 mnemonic[10]; ///< mnemonic
	ADDRESSING_TYPE operand_at[4];///< Addressing method
} OPCODE_PROPERTIES;

#endif /* COMMOND_H_ */
